package cn.scxy.bookcity.controller;

import cn.scxy.bookcity.pojo.dto.AddressDTO;
import cn.scxy.bookcity.pojo.dto.BannerAddDTO;
import cn.scxy.bookcity.pojo.entity.Banner;
import cn.scxy.bookcity.pojo.vo.shoppingCarVO;
import cn.scxy.bookcity.service.IBannerService;
import cn.scxy.bookcity.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Validated
@RequestMapping("/banners")
@Api(tags = "轮播图管理模块")
@RestController
public class BannerController {
    @Autowired
    IBannerService bannerService;

    @ApiOperation("轮播图添加")
    @ApiOperationSupport(order = 100)
    @RequestMapping("/addNew")
    public JsonResult<Void> addNew(BannerAddDTO bannerAddDTO){
        log.debug("开始处理添加轮播图请求,参数:{}",bannerAddDTO);
        bannerService.insert(bannerAddDTO);
        return JsonResult.ok();
    }

    @ApiOperation("轮播图删除")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable int id){
        log.debug("开始处理删除收货地址请求,参数:{}",id);

        bannerService.delete(id);
        return JsonResult.ok();
    }


    @ApiOperation("轮播图修改")
    @ApiOperationSupport(order = 300)
    @PostMapping("/update")
    public JsonResult<Void> update(Banner banner){
        log.debug("开始处理更新收货地址请求,参数:{}",banner);

        bannerService.updateById(banner);
        return JsonResult.ok();
    }

    @ApiOperation("查询轮播图列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult<List<Banner>> list() {
        log.debug("处理查询轮播图请求");
        List<Banner> list = bannerService.list();
        return JsonResult.ok(list);
    }

}
